<html>
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <nav class="navbar navbar-inverse" style="border-radius: 0">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                        aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">智原资源管理系统</a>
            </div>
            <div id="navbar" class="collapse navbar-collapse">

                <ul class="nav navbar-nav">

                    <li class="active">
                        <a href="/index.html">首页</a>
                    </li>
                    <li v-for="d in userResources" v-if="d.pid==0">
                        <a :href="d.url">{{d.name}}</a>
                    </li>

                </ul>
                <ul class="nav navbar-nav navbar-right hidden-sm">
                    <li><a>{{userName}}</a></li>
                    <li><a @click="logout()" href="#">退出</a></li>
                </ul>
            </div>

        </div>
    </nav>

    <div class="container">
        <div class="container" style="text-align: center">
            <h1>道中有道，局中有人</h1>
            <p class="lead">只有顺从自然，才能驾驭自然!<br> 真理的大海，让未发现的一切事物躺卧在我的眼前，任我去探寻!<br>我的那些最重要的发现是受到失败的启示而作出的!</p>
        </div>
    </div>
</div>
<script>
    new Vue({
        el: "#app",
        data: {
            userResources: [],
            userName: ''

        },
        created() {
            this.getUserInfo();

        },
        methods: {
            getUserInfo() {
                var vm = this;
                $.post("userInfo", {}, function (response) {
                    if (response.code == 200) {
                        vm.userName = response.data.name
                        vm.userResources = response.data.role.resourceList

                    } else {
                        location.href = "login.html"
                    }
                })
            },
            logout() {
                $.post("logout", {}, function (response) {
                    location.href = "login.html"
                })
            }
        }
    });
</script>
</body>
</html>